package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 护理项目分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation("护理项目分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> selectPage(@ApiParam(value = "护理项目名称")String name,
                                                                     @ApiParam(value = "护理项目状态") Integer status,
                                                                     @ApiParam(value = "分页页码")@RequestParam(value = "pageNum", defaultValue = "1")Integer pageNum,
                                                                     @ApiParam(value = "每页显示记录数")@RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize

    ){
        PageResponse<NursingProjectVo> pageResponse =nursingProjectService.getByPage(name,status,pageNum,pageSize);
        return success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@ApiParam(value = "护理项目数据传输对象", required = true) @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    /**
     * 根据Id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingProjectVo> getById(@ApiParam(value = "id查询")@PathVariable("id") Long id){
       NursingProjectVo nursingProjectVo =  nursingProjectService.getById(id);
       return success(nursingProjectVo);
    }

    /**
     * 更新护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@ApiParam(value = "护理项目数据传输对象")@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    /**
     * 启用或者禁用
     * @param status
     * @param id
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用和禁用护理项目")
    public ResponseResult startOrStop(@PathVariable Integer status,@PathVariable Long id){
        nursingProjectService.startOrstop(status,id);
        return success();
    }
    /**
     * 根据Id删除护理项目
     * @param id
     */
    @DeleteMapping("{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete(@PathVariable Long id){
        nursingProjectService.delete(id);
        return success();
    }

    /**
     * 查询所有的护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("查询所有的护理项目")
    public ResponseResult<NursingProjectVo> getAll(){
        List<NursingProjectVo> list= nursingProjectService.getAll();
        return success(list);
    }
}
